#include "SQLPartitionByList.h"
#include "../../sql/ast/SQLPartition.h"
#include "../../sql/visitor/SQLASTVisitor.h"
#include "SQLSubPartitionBy.h"
#include "../../utils/listTran.h"
#include "../../utils/log.h"

// @Override
void SQLPartitionByList::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLPartitionByList)))
  {
    SQLObject_list_ptr  tmp1 = ListTran::tran_class<SQLExpr, SQLObject>(columns);
    acceptChild(visitor, tmp1);
    acceptChild(visitor, partitionsCount);
    SQLObject_list_ptr  tmp2 = ListTran::tran_class<SQLPartition, SQLObject>(getPartitions());
    acceptChild(visitor, tmp2);
    acceptChild(visitor, SQLSubPartitionBy_ptr(subPartitionBy));
  }
  visitor->endVisit(SharedObject(SQLPartitionByList));
}

SQLObject_ptr SQLPartitionByList::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLPartitionByList>(new SQLPartitionByList());
  std::shared_ptr<SQLPartitionByList> x = std::dynamic_pointer_cast<SQLPartitionByList>(clone_tmp);
  // SQLPartitionByList *x = new SQLPartitionByList();

  this->cloneTo(x);

  for (SQLExpr_ptr column : *columns)
  {
    SQLExpr_ptr c2 = std::dynamic_pointer_cast<SQLExpr>(column->clone());
    c2->setParent(x);
    x->columns->push_back(c2);
  }

  return x;
}

void SQLPartitionByList::cloneTo(SQLPartitionByList_ptr x)
{
  SQLPartitionBy::cloneTo(x);
}
